import requests
from config import url_file, headers_file


class FileManagement:
    def __int__(self):
        self.url = url_file
        self.headers = headers_file

    @classmethod
    def filesupload(cls, url_file: str, headers=headers_file, data=None, paramspath=None, files=None):
        '''
        summary:文件上传接口
        description:云课堂前端使用
        :param url:
        :param headers:
        :param data:
        :return:
        '''
        url = url_file + f"/fileManagementApi/v1/fileManagement/filesupload/{paramspath}"
        r = requests.post(url=url, headers=headers, data=data, files=files)
        return r

    @classmethod
    def filesupload_pdf(cls, url_file: str, headers=headers_file, data=None, paramspath=None, files=None):
        '''
        summary:文件上传接口
        description:云课堂前端使用
        :param url:
        :param headers:
        :param data:
        :return:
        '''
        url = url_file + f"/fileManagementApi/v1/filemanagement/filesupload/{paramspath}/convertpdf"
        r = requests.post(url=url, headers=headers, data=data, files=files)
        return r

    @classmethod
    def filesupload_pic(cls, url_file: str, headers=headers_file, data=None, paramspath=None, files=None):
        '''
        summary:文件上传并发送转换为图片消息接口
        description:1.云课堂老师端使用，2.小程序使用
        :param url:
        :param headers:
        :param data:
        :return:
        '''
        url = url_file + f"/fileManagementApi/v1/filemanagement/filesupload/{paramspath}/convertpicture"
        r = requests.post(url=url, headers=headers, data=data, files=files)
        return r


if __name__ == '__main__':
    data1 = {
        "uploadFileName": "e98a9422-7160-4245-9b41-a93d6f87f79f",
        "validCode": "a410e759bd5802158ce0c0d793a1d8b6"
    }
    files1 = {
        "file": ("OIP-C.PNG", open(r"..\..\..\file\OIP-C.PNG", "rb"), "image/png")
    }
    re = FileManagement.filesupload(url_file=url_file, data=data1, files=files1, paramspath="teachingcenteradmin_web")
    print(re.status_code, re.url, re.content, re.request.headers, re.request.body, re.request.method, sep="\n")
